class ChartLoader {
    async init() {
        await this.loadChartJS();
        this.renderCharts();
    }

    loadChartJS() {
        return new Promise((resolve) => {
            const script = document.createElement('script');
            script.src = 'https://cdn.jsdelivr.net/npm/chart.js';
            script.onload = resolve;
            document.head.appendChild(script);
        });
    }

    renderCharts() {
        document.querySelectorAll('.chart-container').forEach(container => {
            const ctx = container.querySelector('canvas').getContext('2d');
            const type = container.dataset.chartType || 'line';

            new Chart(ctx, {
                type: type,
                data: this.getChartData(container.dataset),
                options: this.getChartOptions(type)
            });
        });
    }

    getChartData(dataset) {
        // 数据获取逻辑（可根据实际API调整）
        return {
            labels: ['1月', '2月', '3月', '4月', '5月', '6月'],
            datasets: [{
                label: '体温变化',
                data: [36.5, 36.6, 36.8, 37.0, 36.9, 36.7],
                borderColor: '#3498db'
            }]
        };
    }

    getChartOptions(type) {
        const commonOptions = {
            responsive: true,
            maintainAspectRatio: false
        };

        if (type === 'line') {
            return {
                ...commonOptions,
                scales: { y: { beginAtZero: false } }
            };
        }
        return commonOptions;
    }
}